Skip to content

feat: emit inferred aws.alb span for ALB-triggered Lambdas#838

Open
chemystery09 wants to merge 6 commits into
mainfrom
ishara/alb-inferred-span-frsles-851
Open

feat: emit inferred aws.alb span for ALB-triggered Lambdas#838
chemystery09 wants to merge 6 commits into
mainfrom
ishara/alb-inferred-span-frsles-851

Conversation

@chemystery09

@chemystery09 chemystery09 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add create_inferred_span_from_alb_event to emit an inferred aws.alb span (span_type=http, span.kind=server) for ALB-triggered Lambdas, with HTTP request tags (http.method, http.url, http.useragent, etc.).
  • Wire the ALB dispatcher in create_inferred_span on event_type == EventTypes.ALB so both subtypes are covered: single-value headers and multiValueHeaders.
  • Add resolve_alb_request_headers to flatten multiValueHeaders (first value per key, matching datadog-lambda-js) for span creation, HTTP tag extraction, and inbound trace propagation.
  • Fix extract_http_tags for ALB events (no requestContext.stage) so http.url, http.route, and http.useragent are populated and copied onto the inferred span by the wrapper post-response (http.status_code, http.route, peer.service, dd_resource_key).

Closes FRSLES-851.

Test plan

  • pytest tests/test_trigger.py -k application_load_balancer -v
  • pytest tests/test_tracing.py::TestAlbInferredSpan -v
  • pytest tests/test_wrapper.py::TestAlbInferredSpanWrapper -v
  • Single-value and multiValueHeaders ALB fixtures (inferred span, HTTP tags, Datadog + W3C propagation)
  • Wrapper lifecycle: http.status_code, http.route, 5xx errors, peer.service, dd_resource_key, make_inferred_span=False
  • Validate on real AWS ALB + Lambda and attach before/after Datadog trace screenshots (HTTP Requests panel on aws.alb)

Test traces:

Before

image

After
image
image

chemystery09 and others added 2 commits June 25, 2026 16:35
When a Lambda is invoked behind an Application Load Balancer, create an
inferred aws.alb span with HTTP request tags and populate ALB HTTP facet
tags for http.url, http.route, and http.useragent.

FRSLES-851 / APMSVLS-542

Co-authored-by: Cursor <cursoragent@cursor.com>
Cover ALB inferred-span creation, service mapping, inbound trace context,
HTTP trigger tags, and full wrapper lifecycle including status code and
parent/child linkage.

FRSLES-851 / APMSVLS-542

Co-authored-by: Cursor <cursoragent@cursor.com>
@datadog-prod-us1-6

This comment has been minimized.

chemystery09 and others added 2 commits June 26, 2026 13:30
Handle both ALB event subtypes via resolve_alb_request_headers, fix
inbound trace propagation from multiValueHeaders, and expand unit/wrapper
coverage for HTTPS URLs, peer.service, and dd_resource_key.

FRSLES-851

Co-authored-by: Cursor <cursoragent@cursor.com>
Collapse http_url assignment and reformat TestAlbInferredSpanWrapper tests
so check_format.sh passes.

FRSLES-851

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class inferred tracing support for Application Load Balancer (ALB)–triggered Lambdas by creating an aws.alb inferred span and ensuring HTTP tag extraction + inbound trace propagation work for both single-value headers and multiValueHeaders ALB event shapes.

Changes:

  • Add ALB inferred span creation (aws.alb, span_type=http, span.kind=server) and wire it into create_inferred_span.
  • Introduce resolve_alb_request_headers to flatten ALB multiValueHeaders for span creation, HTTP tag extraction, and context propagation.
  • Fix extract_http_tags for ALB events so http.url, http.route, and http.useragent are populated; add/extend tests for inferred spans, mapping, propagation, and wrapper lifecycle.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
datadog_lambda/trigger.py Adds ALB header resolution and improves ALB HTTP tag extraction logic.
datadog_lambda/tracing.py Adds ALB inferred span creation and enables context extraction for ALB multiValueHeaders.
tests/test_trigger.py Extends trigger tag assertions for ALB and adds a multivalue-headers test.
tests/test_tracing.py Adds ALB to propagation coverage and introduces a dedicated inferred-span test suite for ALB.
tests/test_wrapper.py Adds end-to-end wrapper tests validating ALB inferred span behavior and tag copying.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread datadog_lambda/trigger.py
Comment on lines +365 to 369
http_tags["http.route"] = path

if path:
if http_tags.get("http.url"):
http_tags["http.url"] += path
chemystery09 and others added 2 commits June 26, 2026 16:05
Reuse resolve_alb_request_headers for referer tagging so multiValueHeaders
events and lowercase referer keys are handled consistently with other ALB
HTTP facet tags.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@chemystery09 chemystery09 marked this pull request as ready for review June 26, 2026 20:12
@chemystery09 chemystery09 requested review from a team as code owners June 26, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants